package com.zyx.service;

import com.zyx.mapper.AdminMapper;
import com.zyx.mapper.AutoMapper;
import com.zyx.pojo.Admin;
import com.zyx.pojo.AdminExample;
import com.zyx.pojo.Auto;
import com.zyx.pojo.AutoExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管理员表业务逻辑层
 */
@Service
public class AdminService {
    @Resource
    private AdminMapper adminMapper;
    @Resource
    private AutoMapper autoMapper;

    /**
     * 管理员登录
     * @param admin
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)//readOnly=true查询到的数据只读
    public List<Admin> Login(Admin admin) {
        AdminExample example = new AdminExample();
        AdminExample.Criteria criteria = example.createCriteria();
        criteria.andUserEqualTo(admin.getUser());
        criteria.andPassWordEqualTo(admin.getPassWord());
        List<Admin> admins = adminMapper.selectByExample(example);

        return admins;
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)//readOnly=true查询到的数据只读
    public List<Auto> list(){
        AutoExample example = new AutoExample();

        List<Auto> autos = autoMapper.selectByExample(example);
        return autos;
    }

    /*@Transactional(propagation = Propagation.REQUIRED,readOnly = true)//readOnly=true查询到的数据只读
    public int*/
}
